#!/bin/bash
set -e
app="${moduleName}"

# pid store in file
fpid=$(cat "pid/${app}.pid")

# pid grep from running process
rpid=$(pidof "$app")

if [[ "$rpid" == "" ]];then
    echo "$app is not running"
    exit 0
fi

if [[ "$fpid"v != ""v && "$fpid" -eq "$rpid" ]];then
    kill -9 "$fpid"
    echo "$app stopped"
else
    echo "fail to stop $app"
    exit 1
fi

sleep 1

if ! ps -p $fpid > /dev/null;then
    echo "fail to stop $app, please check"
    exit 1
fi

exit 0
